﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
/// <summary>
/// LoginMd5 的摘要说明
/// </summary>
public class LoginMd5
{
	/// <summary>
        /// 自定义md5加密
        /// </summary>
        /// <param name="strTemp"></param>
        /// <returns></returns>
        public static string md5(string strTemp)
        {

            string strMd5 = null;
            if (strTemp != null)
            {
                strMd5 = FormsAuthentication.HashPasswordForStoringInConfigFile(strTemp, "MD5").ToLower();
            }
            else
            {
                strMd5 = "imibsbbs.net,aryouok?";
            }
            return strMd5;
        }
        /// <summary>
        /// 字符串截取，区分半角
        /// </summary>
        /// <param name="stringToSub"></param>
        /// <param name="len"></param>
        /// <returns></returns>
        public static string CutString(string stringToSub, int len)
        {
            ASCIIEncoding ascii = new ASCIIEncoding();
            int tempLen = 0;
            string tempString = "";
            byte[] s = ascii.GetBytes(stringToSub);
            for (int i = 0; i < s.Length; i++)
            {
                if ((int)s[i] == 63)
                {
                    tempLen += 2;
                }
                else
                {
                    tempLen += 1;
                }

                try
                {
                    tempString += stringToSub.Substring(i, 1);
                }
                catch
                {
                    break;
                }

                if (tempLen > len)
                    break;
            }
            //如果截过则加上半个省略号 
            byte[] mybyte = System.Text.Encoding.Default.GetBytes(stringToSub);
            if (mybyte.Length > len)
                tempString += "..";

            return tempString;

        }
        /// <summary>
        /// 字符串替换
        /// </summary>
        /// <param name="strTemp"></param>
        /// <returns></returns>
        public static string repString(string strTemp)
        {
            if (strTemp == null)
                strTemp = "";
            strTemp = strTemp.Replace("'", "").Replace(" ", "").Replace("?", "").Replace(">", "").Replace("&", "").Replace("and", "").Replace(",", "").Replace("*", "").Replace("=", "").Trim();
            return strTemp;
        }
}
